package com.souche.core;

import com.souche.annotation.NotNull;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: mingfeng
 * @Date: 2018/7/4 13:41
 * @Description:
 */
public class Verification {
    public static <T> void notNull(T t) {
        Field[] fields = t.getClass().getDeclaredFields();
        List<String> list = new ArrayList();
        for (Field field : fields) {
            field.setAccessible(true);
            if (field.isAnnotationPresent(NotNull.class)) {
                try {
                    Object oo = field.get(t);
                    if (null == oo) {
                        list.add(field.getName());
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }

        }
        System.out.println("字段" + list.toString() + "不能为null");
    }
}
